package com.qf.service.impl;

import com.qf.mapper.DeviceTypeMapper;
import com.qf.mapper.FarmMapper;
import com.qf.mapper.SysUserMapper;
import com.qf.model.DeviceType;
import com.qf.model.Farm;
import com.qf.model.SysUser;
import com.qf.page.PageResult;
import com.qf.page.QueryPageBean;
import com.qf.service.DeviceTypeService;
import com.qf.service.FarmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
public class DeviceTypeServiceImpl implements DeviceTypeService {
    @Autowired
    private DeviceTypeMapper deviceTypeMapper;


    @Override
    @Transactional
    public int add(DeviceType deviceType) {
        deviceType.setUpdateTime(new Date());
        return deviceTypeMapper.add(deviceType);
    }

    @Override
    public DeviceType findById(int id) {
        return deviceTypeMapper.findById(id);
    }


    @Override
    @Transactional
    public int edit(DeviceType deviceType) {
        deviceType.setUpdateTime(new Date());
        int i = deviceTypeMapper.edit(deviceType);
        return i;
    }


    @Override
    @Transactional
    public int delete(int id) {
        return deviceTypeMapper.delete(id);
    }

    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        Integer CurrentPage = queryPageBean.getCurrentPage();
        Integer PageSize = queryPageBean.getPageSize();
        String queryString = queryPageBean.getQueryString();
        PageResult pageResult = new PageResult();
        List<DeviceType> rows = deviceTypeMapper.findPage((CurrentPage - 1) * PageSize, PageSize, queryString);

        Long total = deviceTypeMapper.count(queryString);
        pageResult.setRows(rows);
        pageResult.setTotal(total);
        return pageResult;
    }

    @Override
    public List<DeviceType> findAll() {
        return deviceTypeMapper.findAll();
    }
}
